/**
 * The Hand class is a subclass of the CardList class and is used to model a hand of cards
 * @author Xu Chen
 */
public abstract class Hand extends CardList{
	/**
	 * a constructor for building a hand with the specified player and list of cards.
	 * @param player is the player playing this hand
	 * @param cards is the cards in this hand
	*/
	public Hand(CardGamePlayer player, CardList cards){
		this.player=new CardGamePlayer();
		this.player=player;
		for(int i=0;i<cards.size();i++) {
			this.addCard(cards.getCard(i));
		}
	}
	
	/**
	 * a player who plays this hand
	*/
	private CardGamePlayer player;
	
	/**
	*a method for retrieving the player of this hand
	*@return this.player as the player of this hand
	*/
	public CardGamePlayer getPlayer() {
		return this.player;
	}
	
	/**
	*a method for retrieving the top card of this hand.
	*@return null (be overridden)
	*/
	public Card getTopCard() {
		return null;
	}
	/**
	*a method for checking if this hand beats a specified hand.
	*@param hand specifies the hand of cards to check whether it can be beaten by this.hand
	*@return true if this hand beats a specified hand
	*/
	public boolean beats(Hand hand) {
		if(hand == null) {
			return false;
		}
		//System.out.println("hand.toString()"+hand.toString());
//		if(this.size()>hand.size()&&hand.isValid()&&this.isValid()) {
//			return true;
//		}
		if(this.size()==hand.size()&&hand.isValid()&&this.isValid()) {
			if(this.size()==1||this.size()==2||this.size()==3) {
				if(this.getTopCard().compareTo(hand.getTopCard()) == 1) {
					return true;
				}else {
					return false;
				}
			}
			if(this.size()==5) {
				if(this.getType()==hand.getType()) {
					if(this.getTopCard().compareTo(hand.getTopCard()) == 1) {
						return true;
					}
				}else {
					if(this.getType()=="StraightFlush") {
						return true;
					}else if(this.getType()=="Quad") {
						if(hand.getType()=="StraightFlush") {
							return false;
						}else {
							return true;
						}
					}else if(this.getType()=="FullHouse") {
						if(hand.getType()=="StraightFlush"||hand.getType()=="Quad") {
							return false;
						}else {
							return true;
						}
					}else if(this.getType()=="Flush") {
						if(hand.getType()=="StraightFlush"||hand.getType()=="Quad"||hand.getType()=="FullHouse") {
							return false;
						}else {
							return true;
						}
					}else {
						return false;
					}
				}
			}
		}

		return false;	
	}
	/**
	 * abstract method
	*a method for checking if this is a valid hand.
	*to be overridden
	*@return true if this hand is valid 
	*/
	public abstract boolean isValid();
	/**
	 * abstract method
	 * a method for returning a string specifying the type of this hand
	 *to be overridden
	 *@return string specifying which type of hand
	*/
	public abstract String getType();
	
	
}